package com.shop2cn.iapi.delivery.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.delivery.parameter.ImportSqDeliverReq;
import com.shop2cn.iapi.delivery.parameter.ImportSqDeliveryInfo;
import com.shop2cn.iapi.delivery.parameter.enums.CheckBizResultEnum;
import com.shop2cn.iapi.delivery.parameter.resp.ExpectCheckResult;
import com.shop2cn.iapi.delivery.parameter.resp.ImportSqDeliveryResp;
import com.shop2cn.iapi.delivery.parameter.resp.ImportSqResult;
import com.shop2cn.iapi.delivery.service.ImportSqCheckCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.shenqi.DGSQBuildProxyChainCallService;
import com.ymttest.business.service.shenqi.SqTradingCallService;
import com.ymttest.database.sharding.db.ext.model.DeliveryPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.OrderStatusLogPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sharding.db.sqlwapper.OrderWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

public class Ts_importSqCheck {

	private static ImportSqDeliverReq importSqDeliverReq;
	private static ImportSqCheckCall importSqCheckCall;

	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("物流发货接口");
	}

	@Before
	public void caseUp() {
		importSqDeliverReq = new ImportSqDeliverReq();
		importSqCheckCall = new ImportSqCheckCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(importSqCheckCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 
	 * @param expectCheckResultList
	 */
	private void verify(List<ExpectCheckResult> expectCheckResultList) {

		ImportSqDeliveryResp resp = importSqCheckCall.getDeliveryResp();

		List<ImportSqResult> billNoCheckResults = resp.getDeliveryResults();

		int i = 0;

		for (ExpectCheckResult expectcheckResultInfo : expectCheckResultList) {

			ImportSqResult checkResult = billNoCheckResults.get(i);

			Logger.verifyEquals(expectcheckResultInfo.isBizSuccess(),
					checkResult.isSuccess(), "校验Success");

			if (checkResult.isSuccess()) {

				// 交易订单状态数据
				verifyOrderStatus(
						expectcheckResultInfo.getImportSqDeliveryInfo(),
						importSqDeliverReq.getGoodsOwnerId(), false);

			}

			Logger.verifyEquals(expectcheckResultInfo.isValidation(),
					checkResult.isValidation(), "校验validation");

			Logger.verifyEquals(expectcheckResultInfo.getBizCode(),
					checkResult.getBizCode(), "校验bizCode");

			Logger.verifyEquals(expectcheckResultInfo.getBizMsg(),
					checkResult.getBizMsg(), "校验bizMsg");

			Logger.verifyEquals(expectcheckResultInfo.getImportSqDeliveryInfo()
					.getBillNos(), checkResult.getBillNos(), "校验billNo");

			Logger.verifyEquals(expectcheckResultInfo.getImportSqDeliveryInfo()
					.getOrderId(), checkResult.getOrderId(), "校验orderId");

			Logger.verifyEquals(expectcheckResultInfo.getImportSqDeliveryInfo()
					.getMobile(), checkResult.getMobile(), "校验mobile");

			Logger.verifyEquals(expectcheckResultInfo.getImportSqDeliveryInfo()
					.getYmtExpressCode() == null ? "Y000"
					: expectcheckResultInfo.getImportSqDeliveryInfo()
							.getYmtExpressCode(), checkResult
					.getYmtExpressCode(), "校验ymtExpressCode");

			i++;
		}
	}

	/**
	 * 校验订单表状态，单主状态操作日志表
	 */
	private void verifyOrderStatus(ImportSqDeliveryInfo info, long sellerId,
			boolean isShippedByXlobo) {

		OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

		long orderId = info.getOrderId();

		// 订单表(order)
		OrderPo ymtOrders = orderShardingWapper.selectOrderbyOrderId(orderId);

		Logger.comment(String.format("验证订单表(order)表 orderId: %s", orderId));

		Logger.verifyEquals(3, ymtOrders.getOrderStatus(), "验证orderStatus");

		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(ymtOrders.getDeliveryTime()) < 2,
				"验证数据库deliveryTime跟系统当前时间差为2分钟内");

		// 订单主状态操作日志表(order_status_log)
		OrderStatusLogPo orderStatusLogPo = orderShardingWapper
				.selectOrderStatusLogByOrderId(orderId);

		Logger.comment("验证订单主状态操作日志表(order_status_log)");

		Logger.verifyEquals("发货", orderStatusLogPo.getMemo(), "验证数据库Memo");
		Logger.verifyEquals(3, orderStatusLogPo.getOrderStatus(),
				"验证数据库OrderStatus");

		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(orderStatusLogPo.getAddTime()) < 2,
				"验证数据库AddTime跟系统当前时间差为2分钟内");

		Logger.verifyEquals(orderId, orderStatusLogPo.getOrderId(),
				"验证数据库OrderId");
		Logger.verifyEquals(sellerId, orderStatusLogPo.getOperator(),
				"验证数据库Operator");

		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		verifyMysqlDb(info, sellerId, ymtOrders.getShenqiLogisticsType());

	}

	/**
	 * 校验 mysql delivery 表
	 * 
	 * @param info
	 */
	private void verifyMysqlDb(ImportSqDeliveryInfo info, long sellerId,
			int logisticsType) {

		long orderId = info.getOrderId();

		DeliveryPo actualDeliveryPo = new OrderWapper()
				.selectDeliveryByOrderId(orderId);

		Logger.comment("校验 delivery 表数据");

		Logger.verifyEquals(
				info.getYmtExpressCode() == null ? "Y000" : info
						.getYmtExpressCode(), actualDeliveryPo
						.getYmtExpressCode(), "验证数据库YmtExpressCode");

		Logger.verifyEquals(false, actualDeliveryPo.getOfficalLogistics(),
				"验证数据库OfficalLogistics");

		Logger.verifyEquals(0, actualDeliveryPo.getRealDeliveryArea(),
				"验证数据库RealDeliveryArea");

		Logger.verifyEquals(orderId, actualDeliveryPo.getOrderId(),
				"验证数据库OrderId");

		Logger.verifyEquals(sellerId, actualDeliveryPo.getSellerId(),
				"验证数据库SellerId");

		Logger.verifyEquals(logisticsType, actualDeliveryPo.getLogisticsType(),
				"验证数据库LogisticsType");

		Logger.verifyEquals(false, actualDeliveryPo.getDeleted(),
				"验证数据库Deleted");

		Logger.verifyEquals(9, actualDeliveryPo.getSource(), "验证数据库Source");

		Logger.verifyEquals(false, actualDeliveryPo.getSourceTrack(),
				"验证数据库SourceTrack");

		Logger.verifyEquals(info.getBillNos().get(0),
				actualDeliveryPo.getBillNo(), "验证数据库BillNo");

		Logger.verifyEquals(logisticsType == 999 ? 3 : 1,
				actualDeliveryPo.getSection(), "验证数据库Section");

		Logger.verifyEquals(info.getMobile(), actualDeliveryPo.getMobile(),
				"验证数据库Mobile");
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_001() {
		Logger.start(true, "货主检查发货成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);

			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optString("IsSuccess"),
					"true", "校验IsSuccess");

			List<ExpectCheckResult> list = new ArrayList<ExpectCheckResult>();

			importSqDeliverReq
					.getImportSqDeliveryInfos()
					.forEach(
							item -> {

								ExpectCheckResult expectCheckResult = new ExpectCheckResult(
										item);

								expectCheckResult
										.setBizCode(CheckBizResultEnum.passed
												.getCode());
								expectCheckResult.setBizMsg("");

								expectCheckResult.setBizSuccess(true);
								expectCheckResult.setValidation(true);

								list.add(expectCheckResult);

							});

			Thread.sleep(3000);
			
			verify(list);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_002() {
		Logger.start(true, "客服发货检查成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(12345);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);

			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optString("IsSuccess"),
					"true", "校验IsSuccess");

			List<ExpectCheckResult> list = new ArrayList<ExpectCheckResult>();

			importSqDeliverReq
					.getImportSqDeliveryInfos()
					.forEach(
							item -> {

								ExpectCheckResult expectCheckResult = new ExpectCheckResult(
										item);

								expectCheckResult
										.setBizCode(CheckBizResultEnum.passed
												.getCode());
								expectCheckResult.setBizMsg("");

								expectCheckResult.setBizSuccess(true);
								expectCheckResult.setValidation(true);

								list.add(expectCheckResult);

							});

			verify(list);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_003() {
		Logger.start(true, "未传入货头id  发货检查失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(12345);

			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optBoolean("IsSuccess"),
					false, "校验IsSuccess");
			Logger.verifyEquals(importSqCheckCall.getBCode(), 100, "校验BCode");
			Logger.verifyEquals(importSqCheckCall.getMsg(),
					"goodsOwnerId:买手ID未提供", "校验Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_004() {
		Logger.start(true, "店主发货，发货失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long sellerId = placeOrderResp.getOrderList().get(0).getOrderPo()
					.getSellerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(sellerId);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optBoolean("IsSuccess"),
					true, "校验IsSuccess");
			Logger.verifyEquals(importSqCheckCall.getDeliveryResp()
					.getDeliveryResults().get(0).getBizMsg(), "找不到订单信息",
					"校验BizMsg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_005() {
		Logger.start(true, "其他货主发货，发货失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(500019955);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optBoolean("IsSuccess"),
					true, "校验IsSuccess");
			Logger.verifyEquals(importSqCheckCall.getDeliveryResp()
					.getDeliveryResults().get(0).getBizMsg(), "找不到订单信息",
					"校验BizMsg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_006() {
		Logger.start(true, "物流为100  发货成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder2(BigDecimal.ZERO, productBean, 1);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(1).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);

			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optString("IsSuccess"),
					"true", "校验IsSuccess");

			List<ExpectCheckResult> list = new ArrayList<ExpectCheckResult>();

			importSqDeliverReq
					.getImportSqDeliveryInfos()
					.forEach(
							item -> {

								ExpectCheckResult expectCheckResult = new ExpectCheckResult(
										item);

								expectCheckResult
										.setBizCode(CheckBizResultEnum.passed
												.getCode());
								expectCheckResult.setBizMsg("");

								expectCheckResult.setBizSuccess(true);
								expectCheckResult.setValidation(true);

								list.add(expectCheckResult);

							});

			verify(list);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_007() {
		Logger.start(true, "不传入运单号，发货失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			//dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(500019955);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optBoolean("IsSuccess"),
					false, "校验IsSuccess");
			Logger.verifyEquals(importSqCheckCall.getMsg(), "importSqDeliveryInfos[0].billNos:运单号未提供",
					"校验Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_008() {
		Logger.start(true, "不传入手机号，发货成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			//dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optString("IsSuccess"),
					"true", "校验IsSuccess");

			List<ExpectCheckResult> list = new ArrayList<ExpectCheckResult>();

			importSqDeliverReq
					.getImportSqDeliveryInfos()
					.forEach(
							item -> {

								ExpectCheckResult expectCheckResult = new ExpectCheckResult(
										item);

								expectCheckResult
										.setBizCode(CheckBizResultEnum.passed
												.getCode());
								expectCheckResult.setBizMsg("");

								expectCheckResult.setBizSuccess(true);
								expectCheckResult.setValidation(true);

								list.add(expectCheckResult);

							});
			
			Thread.sleep(3000);

			verify(list);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_009() {
		Logger.start(true, "不传入物流公司，发货失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			//dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optBoolean("IsSuccess"),
					false, "校验IsSuccess");
			Logger.verifyEquals(importSqCheckCall.getMsg(), "importSqDeliveryInfos[0].expressName:物流公司未提供",
					"校验Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_010() {
		Logger.start(true, "不传入物流公司编码，发货成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			//dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			List<ExpectCheckResult> list = new ArrayList<ExpectCheckResult>();

			importSqDeliverReq
					.getImportSqDeliveryInfos()
					.forEach(
							item -> {

								ExpectCheckResult expectCheckResult = new ExpectCheckResult(
										item);

								expectCheckResult
										.setBizCode(CheckBizResultEnum.passed
												.getCode());
								expectCheckResult.setBizMsg("");

								expectCheckResult.setBizSuccess(true);
								expectCheckResult.setValidation(true);

								list.add(expectCheckResult);

							});
			
			Thread.sleep(5000);

			verify(list);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_importSqCheck_011() {
		Logger.start(true, "订单状态为已支付，发货失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			PayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			Logger.comment("数据准备结束");

			ImportSqDeliveryInfo dInfo = new ImportSqDeliveryInfo();

			dInfo.setOrderId(orderId);

			dInfo.setBillNos(Arrays.asList(TestDataManager.getRandomNum(18)));

			dInfo.setExpressName("sf");
			dInfo.setYmtExpressCode("Y013");

			dInfo.setMobile(TestDataManager.getPhoneNum());

			importSqDeliverReq.setImportSqDeliveryInfos(Lists
					.newArrayList(dInfo));
			importSqDeliverReq.setCdId(0);
			importSqDeliverReq.setGoodsOwnerId(goodsOwnerId);
			importSqCheckCall.setData(importSqDeliverReq);
			importSqCheckCall.callService();

			Logger.verifyEquals(
					importSqCheckCall.getData().optBoolean("IsSuccess"),
					true, "校验IsSuccess");
			Logger.verifyEquals(importSqCheckCall.getDeliveryResp()
					.getDeliveryResults().get(0).getBizMsg(), "当前状态2不能发货.",
					"校验BizMsg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
